#include "StdAfx.h"
#include "OgreEntityBody.h"


OgreEntityBody::OgreEntityBody(Ogre::Entity* entity, Ogre::SceneManager * scnMgr)
{
	this->modelEntity = entity;
	this->sceneMgr = scnMgr;
}


OgreEntityBody::~OgreEntityBody(void)
{

	modelEntity->detachFromParent();
	sceneMgr->destroyEntity(modelEntity);
}




void OgreEntityBody::setPosition(Ogre::Vector3 position)
{
	lastPosition = position;
	if(!position.isNaN())
	{
		modelEntity->getParentSceneNode()->_setDerivedPosition(position);
		
	}
}

Ogre::Vector3 OgreEntityBody::getPosition()
{
	return modelEntity->getParentSceneNode()->_getDerivedPosition();
}

void OgreEntityBody::setOrientation(Ogre::Quaternion orientation)
{
	lastOrientation = orientation;
	modelEntity->getParentSceneNode()->_setDerivedOrientation(orientation);
}

Ogre::Quaternion OgreEntityBody::getOrientation()
{
	return modelEntity->getParentSceneNode()->_getDerivedOrientation();
}


void OgreEntityBody::setLocalPosition(Ogre::Vector3 position)
{
	if(!position.isNaN())
	{
		modelEntity->getParentSceneNode()->setPosition(position);
	}
}

Ogre::Vector3 OgreEntityBody::getLocalPosition()
{
	return modelEntity->getParentSceneNode()->getPosition();
}

void OgreEntityBody::setLocalOrientation(Ogre::Quaternion orientation)
{
	modelEntity->getParentSceneNode()->setOrientation(orientation);
}

Ogre::Quaternion OgreEntityBody::getLocalOrientation()
{
	return modelEntity->getParentSceneNode()->getOrientation();
}


void OgreEntityBody::setLookAt(Ogre::Vector3 target)
{
	modelEntity->getParentSceneNode()->lookAt(target,Ogre::Node::TS_WORLD);
}
	
Ogre::Vector3 OgreEntityBody::getFacingDir()
{
	Ogre::Quaternion ori = getOrientation();

	return ori*Ogre::Vector3::UNIT_Z;
}


Ogre::SceneNode* OgreEntityBody::getParentNode()
{
	return modelEntity->getParentSceneNode();
}


void OgreEntityBody::addForce(Ogre::Vector3 force)
{
}

void OgreEntityBody::addTorque(Ogre::Vector3 torque)
{
}

void OgreEntityBody::killBody()
{
}